package com.chencs.app.model.controller;

import com.alibaba.fastjson.JSON;
import com.chencs.app.AppCommon;
import com.chencs.app.BaseController;
import com.chencs.app.model.service.AppModelService;
import com.chencs.vo.biz.model.ModeModel;
import com.chencs.vo.net.request.RequestBase;
import com.chencs.vo.net.response.AdverResponse;
import com.chencs.vo.net.response.GuideResponse;
import com.chencs.vo.net.response.ModelResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by fangzehua on 2017/7/11.
 */
@RestController
@RequestMapping("/app/index")
public class AppModelController  {


    @Autowired
    private AppModelService appModelService;

    /**
     * 获取首页轮播广告
     * @return
     */
    @RequestMapping(value = "/slideAdver", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String slideAdver(@RequestBody RequestBase requestBase){
        AdverResponse response = new AdverResponse();
        List<ModeModel> list = appModelService.slideAdver();
            try {
                if (list.isEmpty()){
                    response.setCode(AppCommon.NULL);
                    response.setMsg("找不到广告");
                }else{
                    response.setData(list);
                }
            }catch (Exception e){
                    response.setCode(AppCommon.ERROR);
                    response.setMsg("获取轮播图失败");
            }
        return  JSON.toJSONString(response);
    }


    /**
     * 导购模块
     * @return
     */
    @RequestMapping(value = "/guide", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String guide(@RequestBody RequestBase requestBase){
        GuideResponse response = new GuideResponse();
        List<ModeModel> list = appModelService.guide();
        try {
            if (list.isEmpty()){
                response.setCode(AppCommon.NULL);
                response.setMsg("找不到广告");
            }else{
                response.setData(list);
            }
        }catch (Exception e){
            response.setCode(AppCommon.ERROR);
            response.setMsg("获取导购模块失败");
        }

        return  JSON.toJSONString(response);
    }

    /**
     * 导购模块2
     * @return
     */
    @RequestMapping(value = "/guideImage", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String guideImage(@RequestBody RequestBase requestBase){
        GuideResponse response = new GuideResponse();
        List<ModeModel> list = appModelService.guideImage();
        try {
            if (list.isEmpty()){
                response.setCode(AppCommon.NULL);
                response.setMsg("找不到图块");
            }else{
                response.setData(list);
            }
        }catch (Exception e){
            response.setCode(AppCommon.ERROR);
            response.setMsg("获取导购图快失败");
        }
        return  JSON.toJSONString(response);
    }

    /**
     * 获取欢迎界面广告图
     * @return
     */
    @RequestMapping(value = "/getWelcomeAd", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String getWelcomeAd(@RequestBody RequestBase requestBase){
        ModelResponse response = new ModelResponse();
        ModeModel modeModel = appModelService.getWelcomeAd();
        try {
            if(modeModel==null){
                response.setCode(AppCommon.NULL);
                response.setMsg("找不欢迎广告");
            }else{
                response.setModeModel(modeModel);
            }
        }catch (Exception e){
            e.printStackTrace();
            response.setCode(AppCommon.ERROR);
            response.setMsg("获取欢迎广告失败");
        }
        return  JSON.toJSONString(response);
    }

    /**
     * 获取弹窗广告AD
     * @return
     */
    @RequestMapping(value = "/getPopupAd", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String getPopupAd(@RequestBody RequestBase requestBase){
        ModelResponse response = new ModelResponse();
        ModeModel modeModel = appModelService.getPopupAd();
        try {
            if(modeModel==null){
                response.setCode(AppCommon.NULL);
                response.setMsg("找不弹窗广告");
            }else{
                response.setModeModel(modeModel);
            }
        }catch (Exception e){
            e.printStackTrace();
            response.setCode(AppCommon.ERROR);
            response.setMsg("获取弹窗广告失败");
        }
        return  JSON.toJSONString(response);
    }





    /**
     * 获取配置
     * @return
     */
    @RequestMapping(value = "/config", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String configure(@RequestBody RequestBase requestBase){

        return  "";
    }



}
